package com.wjx.happensbefore.threadinterrupt;

import com.wjx.happensbefore.Utils;

public class ThreadInterrupt {
    private static boolean stopped = false;

    public static void main(String[] args) {
        Thread getter = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    if (Thread.currentThread().isInterrupted()) {
                        if (stopped) {
                            System.out.println("getter stopped.");
                            break;
                        }
                    }
                }
            }
        }, "getter");
        Thread updater = new Thread(new Runnable() {
            @Override
            public void run() {
                Utils.sleep(1000);
                stopped = true;
                getter.interrupt();
                System.out.println("updater set stop true.");
            }
        }, "updater");

        updater.start();
        getter.start();
    }

}
